package graphics.main;
import java.io.Serializable;

import tools.Point;
import tools.id.IdSystem;

import graphics.objects.GraphicsObject;
import graphics.system.Renderer;
public class Graphics implements Serializable {
	transient Renderer renderer;
	private IdSystem<GraphicsObject> graphicsObjects;
	public int numGraphicsObjects;
	public Graphics() {
		graphicsObjects = new IdSystem<GraphicsObject>();
	}
	public void setRenderer(Renderer r) {
		renderer = r;
		if (r == null)
			return;
		for (int i = 0; i < numGraphicsObjects; i++) {
			GraphicsObject o = getGraphicsObject(i);
			r.addObject(o);
		}
	}
	public void handle() {
		if (renderer != null)
			for (int i = 0; i < 1; i++)
				renderer.render();
	}
	public void addGraphicsObject(GraphicsObject g) {
		numGraphicsObjects++;
		renderer.addObject(g);
		graphicsObjects.add(g);
	}
	public void remGraphicsObject(GraphicsObject g) {
		numGraphicsObjects--;
		renderer.removeObject(g);
		graphicsObjects.remove(g);
	}
	public GraphicsObject getGraphicsObject(int index) {
		return graphicsObjects.get(index);
	}
	public GraphicsObject getGraphicsObjectById(Integer id) {
		return graphicsObjects.getById(id);
	}
	public boolean contains(GraphicsObject o) {
		return graphicsObjects.contains(o);
	}
	public boolean containsGraphicsObjectId(int grId) {
		return graphicsObjects.containsId(grId);
	}
	public void setCampos(Point pos) {
		renderer.setCameraPosition(pos);
	}
}
